package site.qjdb.pojo;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * 	订单子项
 * 
 * */
public class OrderItem {
	private Integer iid; // 订单子项id
	private Goods goods; // 对应的商品
	private Integer count; // 购买的商品数量
	private String realSubtotal; // 商品小计
	private Integer dbSubtotal; // 数据库中存储的商品小计
	private Integer oid; // 所属的订单id
	private Integer state; // 订单子项状态，0：正常态

	public OrderItem() {
	}

	public String getRealSubtotal() {
		if (this.realSubtotal == null && this.dbSubtotal != null) {
			// 从数据库获取Integer类型数据，转成String类型。目的：用于前端显示
			Double _realSubtotal = this.dbSubtotal / 100d;
			// 0.00表示保留后两位，它的处理方式是直接截掉不要的尾数，不四舍五入。
			DecimalFormat df = new DecimalFormat("0.00");
			this.realSubtotal = df.format(_realSubtotal);
		}
		return realSubtotal;
	}

	public void setRealSubtotal(String realSubtotal) {
		this.realSubtotal = realSubtotal;
	}

	public Integer getDbSubtotal() {
		if (this.dbSubtotal == null && this.realSubtotal != null) {
			// 从web端获取String类型数据，转成Integer类型。目的：1.存储到数据库 2.进行运算
			BigDecimal bigDecimal = new BigDecimal(realSubtotal);
			Double _realSubtotal = bigDecimal.setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
			Double price = _realSubtotal * 100;
			this.dbSubtotal = price.intValue();
		}
		return dbSubtotal;
	}

	public void setDbSubtotal(Integer dbSubtotal) {
		this.dbSubtotal = dbSubtotal;
	}

	public Integer getIid() {
		return iid;
	}

	public void setIid(Integer iid) {
		this.iid = iid;
	}

	public Goods getGoods() {
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public Integer getOid() {
		return oid;
	}

	public void setOid(Integer oid) {
		this.oid = oid;
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	@Override
	public String toString() {
		return "OrderItem [iid=" + iid + ", goods=" + goods + ", count=" + count + ", realSubtotal=" + realSubtotal
				+ ", dbSubtotal=" + dbSubtotal + ", oid=" + oid + ", state=" + state + "]";
	}

}
